package com.sy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sy.dto.CoursedetailPageQueryDTO;
import com.sy.mapper.CoursedetailMapper;
import com.sy.pojo.Coursedetail;
import com.sy.result.PageResult;
import com.sy.service.CoursedetailService;
import org.springframework.stereotype.Service;

@Service
public class CoursedetailServiceImpl extends ServiceImpl<CoursedetailMapper, Coursedetail> implements CoursedetailService {
    @Override
    public PageResult findAll(CoursedetailPageQueryDTO cdPage) {
        Page<Coursedetail> page=new Page<>(cdPage.getPage(),cdPage.getPageSize());

        LambdaQueryWrapper<Coursedetail> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Coursedetail::getCid,cdPage.getCid())
                //根据排序号和时间两列进行排序，排序号一样的话，再根据时间升序排序
                .orderByAsc(Coursedetail::getSort,Coursedetail::getCreateTime);

        page=this.page(page,queryWrapper);
        return new PageResult(page.getTotal(),page.getRecords());
    }
}
